package cn.sylinx.hbatis.db.dialect.sql;

import cn.sylinx.hbatis.db.dialect.DbType;
import cn.sylinx.hbatis.ext.tool.RepositoryTools;
import cn.sylinx.hbatis.log.GLog;

public class MysqlSqlBuilder extends DefaultSqlBuilder {
	@Override
	protected String[] getEscapeChar() {
		return new String[] { "`", "`" };
	}

	@Override
	public String[] buildCreateTableDDL(Class<?> clz) {

		String ddl = RepositoryTools.getInstance().generateTableDdlSql(DbType.MYSQL, clz);
		GLog.debug("dbType:{}, ddl: {}",DbType.MYSQL, ddl);
		String[] ddlArray = ddl.split(";\n");
		return ddlArray;
	}

	@Override
	public String[] buildModifyTableColumnDDL(Class<?> clz, String prop) {
		String ddl = RepositoryTools.getInstance().generateModifyTableColumnDDL(DbType.MYSQL, clz, prop);
		if (ddl == null) {
			return null;
		}
		GLog.debug("dbType:{}, ddl: {}",DbType.MYSQL, ddl);
		String[] ddlArray = ddl.split(";\n");
		return ddlArray;
	}

	@Override
	public String[] buildAddTableColumnDDL(Class<?> clz, String prop) {
		String ddl = RepositoryTools.getInstance().generateAddTableColumnDDL(DbType.MYSQL, clz, prop);
		GLog.debug("dbType:{}, ddl: {}",DbType.MYSQL, ddl);
		String[] ddlArray = ddl.split(";\n");
		return ddlArray;
	}
}
